<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('AdminContest/index')}">赛事管理</a></li>
        <li>
            <a href="{:url('AdminContest/add')}">添加赛事</a>
        </li>
        <li class="active"><a href="#">编辑赛事</a></li>
    </ul>
    <form action="{:url('AdminContest/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">

                    <tr>
                        <th width="100">分类<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" style="width:400px;" required
                                   value="{:implode(' ',$contest_categories)}"
                                   placeholder="请选择分类" onclick="doSelectCategory();" id="js-categories-name-input"
                                   readonly/>
                            <input class="form-control" type="hidden" value="{$contest_category_ids}"
                                   name="categories"
                                   id="js-categories-id-input"/>
                        </td>
                    </tr>
                    <tr>
                        <th>标题<span class="form-required">*</span></th>
                        <td>
                            <input type="hidden" name="id" value="{$contest.id}">
                            <input class="form-control" type="text" name="title"
                                   id="title" required value="{$contest.title}" placeholder="请输入标题"/>
                        </td>
                    </tr>
                    <tr>
                        <th>关键词</th>
                        <td>
                            <input class="form-control" type="text" name="keywords" id="keywords" value="{$contest.keywords}"
                                   placeholder="请输入关键字">
                            <p class="help-block">多关键词之间用英文逗号隔开</p>
                        </td>
                    </tr>
                    <tr>
                        <th>报名时间</th>
                        <td>
                            <input type="text" class="form-control js-bootstrap-datetime select_time" name="apple_start"
                                   value="{:date('Y-m-d',$contest.apple_start)}" placeholder="请选择开始时间"
                                   style="width: 200px;display: inline;" autocomplete="off">-
                            <input type="text" class="form-control js-bootstrap-datetime select_time" name="apple_end"
                                   value="{:date('Y-m-d',$contest.apple_end)}" placeholder="请选择结束时间"
                                   style="width: 200px;display: inline;" autocomplete="off">
                        </td>
                    </tr>
                    <tr>
                        <th>评审时间</th>
                        <td>
                            <input type="text" class="form-control js-bootstrap-datetime select_time" name="review_start"
                                   value="{:date('Y-m-d',$contest.review_start)}" placeholder="请选择开始时间"
                                   style="width: 200px;display: inline;" autocomplete="off">-
                            <input type="text" class="form-control js-bootstrap-datetime select_time" name="review_end"
                                   value="{:date('Y-m-d',$contest.review_end)}" placeholder="请选择结束时间"
                                   style="width: 200px;display: inline;" autocomplete="off">
                        </td>
                    </tr>
                    <tr>
                        <th>内容</th>
                        <td>
                            <script type="text/plain" id="desc" name="desc">{:htmlspecialchars_decode($contest.desc)}</script>
                        </td>
                    </tr>
                </table>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                        <a class="btn btn-default" href="{:url('AdminContest/index')}">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <table class="table table-bordered">
                    <tr>
                        <th><b>缩略图</b></th>
                    </tr>
                    <tr>
                        <td>
                            <div style="text-align: center;">
                                <input type="hidden" name="picture" id="picture" value="{$contest.picture}">
                                <a href="javascript:uploadOneImage('图片上传','#picture');">
                                    <if condition="empty($contest.picture)">
                                        <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                             id="picture-preview"
                                             width="135" style="cursor: pointer"/>
                                        <else/>
                                        <img src="{:cmf_get_image_preview_url($contest.picture)}"
                                             id="picture-preview"
                                             width="135" style="cursor: pointer"/>
                                    </if>
                                </a>
                                <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
                            </div>
                        </td>
                    </tr>
<!--                    <tr>-->
<!--                        <th><b>发布时间</b></th>-->
<!--                    </tr>-->
<!--                    <tr>-->
<!--                        <td>-->
<!--                            <input class="form-control js-bootstrap-datetime" type="text" name="published_time"-->
<!--                                   value="{:date('Y-m-d H:i:s',$contest.published_time)}">-->
<!--                        </td>-->
<!--                    </tr>-->
                    <tr>
                        <th><b>状态</b></th>
                    </tr>
                    <tr>
                        <td>
                            <if condition="$contest.status eq 1">
                                <input type="checkbox" name="status" value="1" checked>当前赛事
                            <else/>
                                <input type="checkbox" name="status" value="1">当前赛事
                            </if>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script src="__STATIC__/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">
    $(function () {
        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('desc');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#picture').val('');
        });

    });

    $('.select_time').datetimepicker({
        minView: "month", //选择日期后，不会再跳转去选择时分秒
        language:  'zh-CN',
        format: 'yyyy-mm-dd',
        todayBtn:  1,
        autoclose: 1,
    });

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminContestCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
</body>
</html>
